<template>
	<view class="pages">
		<view class="nav">
			<view class="nav_item" @click="changeMore">{{$t('mine.collect.Multiple')}}
				<view :class="checkShow?'check active':'check'">
					<uni-icons type="checkmarkempty" color="#fff" size="8"></uni-icons>
				</view>
			</view>
		</view>
		<view class="goodsList" v-if="collectList.length!=0">
			<view class="goods_items" v-for="item in collectList">
				<view class="goods_item_leftimg" @click="toDetail(item.good_id)">
					<image style="width: 100%;height: 100%;" :src="item.mainimg"></image>
				</view>
				<view class="goods_item_right">
					<view class="item_top">{{item.name}}</view>
					<view class="item_bottom">
						<view class="price">￥{{item.price}}</view>
						<view v-if="checkShow" :class="checkList.indexOf(item.id)!=-1?'check active':'check'" @click="check(item.id)">
							<uni-icons type="checkmarkempty" color="#fff" size="8"></uni-icons>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="no_list" v-else>
			<u-empty mode="favor" :text="$t('mine.collect.No')" icon="http://cdn.uviewui.com/uview/empty/car.png"></u-empty>
		</view>
		<view class="bottom" v-show="checkShow">
			<view class="text" @click="userCollectcancel">{{$t('mine.collect.Unbookmark')}}</view>
		</view>
	</view>
</template>
<script>
	import { userCollect, userCollectcancel } from '@/api/api.js'
	export default {
		data() {
			return {
				checkShow: false,
				collectList: [],
				// 选中的数组
				checkList: []
			}
		},
		onShow() {
			this.userCollect()
			uni.setNavigationBarTitle({
				title: this.$t('list.Serve')
			})
		},
		methods: {
			changeMore() {
				this.checkList = []
				this.checkShow = !this.checkShow
			},
			toDetail(id){
				uni.navigateTo({
					url:`/pages/shop/goodDetail/goodDetail?id=${id}`
				})
			},
			check(id) {
				if (this.checkShow) {
					if (this.checkList.indexOf(id) == -1) {
						this.checkList.push(id)
					} else {
						this.checkList = this.checkList.filter(item => {
							return item != id
						})
					}
				}
			},
			userCollect(){
				userCollect({
					token: uni.getStorageSync('token')
				}).then(res=>{
					this.collectList = res.data.data.data
				})
			},
			userCollectcancel(){
				userCollectcancel({
					token: uni.getStorageSync('token'),
					ids: this.checkList.toString()
				}).then(res=>{
					uni.showToast({
						title: res.data.msg,
						icon: "none"
					})
					setTimeout(() => {
						this.checkShow = false
						this.userCollect()
					}, 500)
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.pages{
		padding: 1rpx;
		box-sizing: border-box;
	}
	.check {
		width: 28rpx;
		height: 28rpx;
		border: 1rpx solid #ddd;
		border-radius: 28rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 10rpx;
	}

	.active {
		border: none;
		background-color: #00C2C2;
	}

	.nav {
		width: 92%;
		height: 70rpx;
		position: fixed;
		left: 4%;
		right: 0;
		display: flex;

		.nav_item {
			display: flex;
			justify-content: center;
			align-items: center;
			color: #53cbc5;
			font-weight: bold;

			.check {
				width: 28rpx;
				height: 28rpx;
				border: 1rpx solid #ddd;
				border-radius: 28rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-left: 10rpx;
			}

			.active {
				border: none;
				background-color: #00C2C2;
			}
		}
	}

	.goodsList {
		padding-top: 100rpx;
		width: 92%;
		margin: 0 auto;

		.goods_items {
			width: 100%;
			height: 190rpx;
			display: flex;
			justify-content: space-between;
			padding-bottom: 15rpx;
			margin-bottom: 15rpx;
			border-bottom: 1rpx solid #f5f5f5;

			.goods_item_leftimg {
				width: 170rpx;
				height: 170rpx;
				flex-shrink: 0;
				display: flex;
				justify-content: center;
				align-items: center;
				border: 1rpx solid #ebebeb;
				margin-right: 20rpx;

				image {
					width: 150rpx;

				}
			}

			.goods_item_right {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				flex-grow: 1;

				.item_top {
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				.item_bottom {
					display: flex;
					justify-content: space-between;
					font-weight: bold;
				}
			}
		}
	}
	
	.no_list{
		margin-top: 100rpx;
	}
	
	.bottom {
		width: 100%;
		height: 120rpx;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		display: flex;
		justify-content: center;

		.text {
			width: 90%;
			height: 90rpx;
			background-color: #00C2C2;
			color: #fff;
			font-weight: bold;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>